package com.lyn.auxiliarytool.contract;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池
 * @author longyn 2022/11/29
 * @version 1.0.0
 */
public class ThreadPool {

    private static class ThreadPoolTypeClass{
        private static final ThreadPool in = new ThreadPool();
    }

    private final ThreadPoolExecutor poolExecutor;

    public ThreadPool() {
        Runtime runtime = Runtime.getRuntime();
        int availableProcessors = runtime.availableProcessors();
        poolExecutor = new ThreadPoolExecutor(1
                ,availableProcessors+1
                ,3, TimeUnit.SECONDS
                ,new ArrayBlockingQueue<>(availableProcessors+1));

    }

    public static ThreadPoolExecutor get(){
        return ThreadPoolTypeClass.in.poolExecutor;
    }
}
